package com.fitns.user.controller.baseConfig;

import com.fitns.user.conf.Resp;
import com.fitns.user.dto.baseConfig.WorkTimeDTO;
import com.fitns.user.dto.baseConfig.WorkTimeVO;
import com.fitns.user.service.baseConfig.WorkTimeService;
import com.fitns.user.utils.ResultData;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 *Created by ye on 2018/8/1
 *
 */

@RestController
@CrossOrigin //解决前后端对接跨域问题
@RequestMapping("/workTime")
@Api(description = "作业时间")
public class WorkTimeController {

    @Autowired
    private WorkTimeService workTimeService;

    @PostMapping("/insert")
    @ApiOperation("新增")
    public ResultData insert(@RequestBody WorkTimeDTO workTimeDTO){
        WorkTimeVO workTimeVo = workTimeService.insert(workTimeDTO);
        return new ResultData(200,"SUCESS",workTimeVo,"");
    }

    @PutMapping("/modify")
    @ApiOperation("修改")
    public ResultData modify(@RequestBody WorkTimeDTO workTimeDTO){
        WorkTimeVO workTimeVo = workTimeService.modify(workTimeDTO);
        if(StringUtils.isEmpty(workTimeVo)){
            return new ResultData( 300,"DEFAULT",workTimeVo,"");
        }
        return new ResultData(200,"SUCESS",workTimeVo,"");
   }

    @GetMapping("/select")
    @ApiOperation("查询列表")
    public Object select( WorkTimeDTO workTimeDTO){
        PageInfo<WorkTimeVO> workTimeVoList= workTimeService.selectList(workTimeDTO);
        workTimeVoList.setPageSize(workTimeDTO.getPageSize());
        return Resp.page(workTimeVoList);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除")
    public ResultData delete(@RequestParam("id") Long id){
        workTimeService.delete(id);
        return new ResultData(200,"SUCESS",null,"删除成功");
    }

    @GetMapping("/selectById")
    @ApiOperation("通过id查询数据")
    public Object selectById(@RequestParam("id") Long id){
        return workTimeService.selectById(id);
    }


}
